package com.wwwc.index.web.servlet;

import java.io.*;
import java.util.*;
import java.net.URLEncoder;
import java.awt.*;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.FontMetrics;
import javax.servlet.*;
import javax.servlet.http.*;

public final class PasswordImageServlet extends ImageServlet

{
    public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
    {
	res.setHeader("Pragma", "no-cache");
	res.setHeader("Cache-Control", "no-cache");
	res.setDateHeader("Expires", 0);
	String page_head  = req.getHeader("Referer");

	HttpSession session = req.getSession(true);	
	Hashtable ps_hashtable = new Hashtable ();

	ps_hashtable.put("1","found");
	ps_hashtable.put("2","good");
	ps_hashtable.put("3","Think");
	ps_hashtable.put("4","Build");
	ps_hashtable.put("5","beef");
	ps_hashtable.put("6","news");
	ps_hashtable.put("7","seek");
	ps_hashtable.put("8","Jobs");
	ps_hashtable.put("9","thank");
	ps_hashtable.put("10","words");
	ps_hashtable.put("11","Index");
	ps_hashtable.put("12","Java");
	ps_hashtable.put("13","J2EE");
	ps_hashtable.put("14","JSDK");
	ps_hashtable.put("15","Image");
	ps_hashtable.put("16","blank");
	ps_hashtable.put("17","Bank");
	ps_hashtable.put("18","CAFE");
	ps_hashtable.put("19","look");
	ps_hashtable.put("20","join");
	ps_hashtable.put("21","Found");
	ps_hashtable.put("22","Good");
	ps_hashtable.put("23","think");
	ps_hashtable.put("24","Build");
	ps_hashtable.put("25","Beef");
	ps_hashtable.put("26","News");
	ps_hashtable.put("27","Seek");
	ps_hashtable.put("28","Jobs");
	ps_hashtable.put("29","Thank");
	ps_hashtable.put("30","words");
	ps_hashtable.put("31","Index");
	ps_hashtable.put("32","Java");
	ps_hashtable.put("33","J2ee");
	ps_hashtable.put("34","Jsdk");
	ps_hashtable.put("35","image");
	ps_hashtable.put("36","blank");
	ps_hashtable.put("37","bank");
	ps_hashtable.put("38","CAFE");
	ps_hashtable.put("39","Look");
	ps_hashtable.put("40","Join");

	Random r = new Random();
	String pin= Integer.toString(r.nextInt(40)+1);
	
	sendImage(res, createPassString((String)ps_hashtable.get(pin)));
	//session.setAttribute("img_key",pin);
	session.setAttribute("img_key",ps_hashtable.get(pin));
    }

    public Image createPassString(String pin_str)
    {

	Image img = createImage(100, 30, Color.black);
	Graphics g = img.getGraphics();

	g.setColor(Color.GRAY);
	g.fillRect(0, 0, 100, 30);
	
	g.setColor(Color.GREEN);
	g.setFont(new Font("Serif", Font.BOLD, 24));
	g.drawString(pin_str,  10, 20);
	
	return img;
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
	doPost(request, response);
    }
}






